package huytq.gs.view;

import com.example.paralletkill.R;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.Gallery.LayoutParams;
import android.widget.TextView;

public class ImageAdapter extends BaseAdapter {
	private LayoutInflater mInflater;
    int mGalleryItemBackground;
    private Context mContext;
    private ImageView[] iv;

    private Integer[] mImageIds = {
        	R.drawable.thumnailmap ,
        	R.drawable.thumnailmap1 ,
        	R.drawable.thumnailmap2,
        	R.drawable.thumnailmap4 ,
        	R.drawable.thumnailmap5
        };
    
    public static String[] str_map = {"Đảo Âm Dương", "Lâu Đài Quỷ", "Động Không Đáy",
    	"Núi Cô Độc", "Hồ Thác Bạc"};
    
//    private Integer[] mImageIds = {
//        	R.drawable.back_1 ,
//        	R.drawable.back_1 ,
//        	R.drawable.back_1 ,
//        	R.drawable.back_1 ,
//        	R.drawable.back_1 ,
//        	R.drawable.back_1 ,
//        	R.drawable.back_1 ,
//        	R.drawable.back_1 ,
//        };
        
    private int cnt;

    public ImageAdapter(Context c) {
        mContext = c;
        cnt = mImageIds.length;
        iv = new ImageView[cnt];
       
        mInflater = (LayoutInflater) c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
       
        for(int i=0; i<cnt; i++){
        	 iv[i] = new ImageView(mContext);
        	 iv[i].setImageResource(mImageIds[i]);
        	 iv[i].setScaleType(ImageView.ScaleType.FIT_XY);
        	 iv[i].setLayoutParams(new Gallery.LayoutParams(200, 200));
        }
    }

    public int getCount() {
        return cnt;
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = mInflater.inflate(
					R.layout.image_custom, null);
			holder.img = (ImageView) convertView.findViewById(R.id.img);
			holder.tv = (TextView) convertView.findViewById(R.id.tv);
			
			convertView.setTag(holder);
		}
		else {
			holder = (ViewHolder) convertView.getTag();
		}
		holder.tv.setText(str_map[position]);
		holder.img.setId(position);
		
		holder.tv.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				// TODO Auto-generated method stub
				
			}
		});
		
		holder.img.setImageResource(mImageIds[position]);
//		holder.tv.setChecked(thumbnailsselection[position]);
		holder.id = position;
		holder.tv.setEnabled(false);
//		GalleryViewTest.tv_ten.setText(str_map[position])
		Log.e("getview", "getview: "+position);
		return convertView;
	}
    
    class ViewHolder {
		public ImageView img;
		public TextView tv;
		int id;
	}
    
}